﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Printing;
using System.Windows.Threading;

namespace A_PrintBlankForm
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            PD = new PrintDocument();
            PD.PrintPage += new EventHandler<PrintPageEventArgs>(PD_PrintPage);
            this.DataContext = this;
        }

        public int MemberID { get; set; }

        void PD_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.PageVisual = Pages.Dequeue();
            e.HasMorePages = Pages.Count != 0;
        }
        Queue<UIElement> Pages = new Queue<UIElement>();
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Queue<UIElement> Blocks = new Queue<UIElement>();

            Blocks.Enqueue(new P_PersonalDetails.MembershipDetails() { MemberID = MemberID });
            Blocks.Enqueue(new P_PersonalDetails.SlalomRanking() { MemberID = MemberID });
            Blocks.Enqueue(new P_PersonalDetails.Qualifications() { MemberID = MemberID });
            Blocks.Enqueue(new P_PersonalDetails.PersonalInfo() { MemberID = MemberID });
            Blocks.Enqueue(new P_PersonalDetails.ContactNumbers() { MemberID = MemberID });
            Blocks.Enqueue(new P_PersonalDetails.MedicalAndEmergency() { MemberID = MemberID });

            var SP1 = new StackPanel();
            SP1.Children.Add(Blocks.Dequeue());
            SP1.Children.Add(Blocks.Dequeue());
            SP1.Children.Add(Blocks.Dequeue());
            Pages.Enqueue(SP1);

            var SP2 = new StackPanel();
            SP2.Children.Add(Blocks.Dequeue());
            SP2.Children.Add(Blocks.Dequeue());
            Pages.Enqueue(SP2);

            var SP3 = new StackPanel();
            SP3.Children.Add(Blocks.Dequeue());
            Pages.Enqueue(SP3);
        }
        PrintDocument PD;

        private void Print_Click(object sender, RoutedEventArgs e)
        {
            PD.Print("Membership Form");
        }
    }
}
